home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 10203 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.6 KB

  1. Path: user1.mnsinc.com!huang
  2. From: huang@mnsinc.com (Szu-Wen Huang)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Tradition or what?
  5. Date: 16 Mar 1996 00:10:15 GMT
  6. Organization: Monumental Network Systems
  7. Message-ID: <4id0t7$9nr@news1.mnsinc.com>
  8. References: <4g0elg$mdr@redstone.interpath.net> <4hpd8a$d70@alterdial.UU.NET> <1996Mar8.153250.115645@kuhub.cc.ukans.edu> <4hqfug$19l@news.interpath.net> <4hqkso$gno@news1.mnsinc.com> <1996Mar15.163722.6685@pyra.co.uk>
  9. NNTP-Posting-Host: user.mnsinc.com
  10. X-Newsreader: TIN [version 1.2 PL2]
  11.  
  12. Mark Bluemel (markb@pyramid.com) wrote:
  13. : Szu-Wen Huang (huang@mnsinc.com) wrote:
  14.  
  15. : : Let me join in.  I use magic numbers for states in parsing tables,
  16. : : and will shoot anybody who suggests I should #define state numbers.
  17. : : I hope we buried the issue, now that I've given one good place to
  18. : : use magic numbers instead of #define's.
  19.  
  20. : May I respectfully suggest that #defines would be clearer and enumerations
  21. : clearer still ?
  22.  
  23. No, it won't be, because the states don't always have logical
  24. significance.  For example, the parser state machine for a simple
  25. regular expression [A-Za-z]*=[0-9]* might look:
  26.  
  27. switch (state) {
  28.   case 0: if (isalpha(input)) ...
  29.           else if (input == '=') state = 1;
  30.           break;
  31.   case 1: if (...
  32. }
  33.  
  34. In this case, I don't believe clarify is an issue, first of all,
  35. because without the state diagram, the code is next to useless
  36. to a reader (these code tend to be long).  A practical parser
  37. would have many more states, and #defining those would both be
  38. a bother and serve no practical purpose in terms of readability.
  39. In this case, what would you name the states?
  40.  
  41.